<?php
include('upload_crop.php');

$upload_crop = new Upload_crop(array(
	'wwwroot' => 'D:/web/www/img.123tsg.com',
	'dstroot' => 'book_m',
	'tmproot' => 'book_m_tmp'
));
$upload_crop->imagelimit = array('jpg', 'JPG');
if (isset ($_POST ['act'])) {
	$action = $_POST ['act'];
	switch ($action) {
		case 'upload' :
			echo $upload_crop->upload();
			break;
		case 'delete' :
			echo $upload_crop->del('hehe');
			break;
		case 'crop' :
			echo $upload_crop->crop();
			break;
		default :
			//
			break;
	}
}
/**
 * 初始化临时文件夹
 * 如果图片已经超过今天文件夹的容量
 * 自动向明天的文件夹添加,跨月判断
 * 可能永远不会进入第2层递归(每天有超过5000+的图片录入?!)
 */
function init_tmp_folder(&$_y, &$_m, &$_d, $_path)
{
	$destination_tmp_folder = '/' . $_path . '/' . $_y . $this->addstr($_m) . '/' . $this->addstr($_d) . '/'; // 上传文件临时路径
	$realfileDir = $this->wwwRoot . $destination_tmp_folder;
	if (!file_exists($realfileDir)) {
		$this->create_folder($realfileDir);
	} else {
		//空文件夹默认有[.][..]两个文件
		$currentCount = count(scandir($realfileDir));
		if (($currentCount - 2) >= $this->limit) {
			if ($_d == $this->month_n_day($_y, $_m)) {
				if (12 == $_m) {
					$_y++;
					$_m = 1;
					$_d = 1;
				} else {
					$_m++;
					$_d = 1;
				}
			} else {
				$_d++;
			}
			file_put_contents($this->wwwRoot . '/' . $_path . '/' . $this->positionInfo, $_y . $this->addstr($_m) . $this->addstr($_d));
			$destination_tmp_folder = $this->init_tmp_folder($_y, $_m, $_d, $_path);
		}
	}

	return $destination_tmp_folder;
}